<template>
  <div>
    <el-select :value-key="'id'" v-model="selectValue" v-bind="$attrs">
      <el-option v-for="item in options" :key="item" :value-key="item.id" :label="item.nickname"
        :value="isid == 0 ? item : item.id" :disabled="isDisabled(item)" />
    </el-select>
  </div>
</template>
<script setup>
import { getRoleauthorize } from "@/api/manage/projectManagementes/user-authorization/index";
const options = ref([]);
import { usePageVariablesStoreHook } from "@/store/modules/pageVariables";
const usePageVariablesStore = usePageVariablesStoreHook();
const props = defineProps({
  isid: {
    type: Number,
    default: 0
  },
  isall: {
    type: Number,
    default: 0
  },
  modelValue: {
    type: Object,
    default: null
  },
  projectId: {
    type: Number,
    default: 0
  }
});
const emit = defineEmits(["update:modelValue"]);
const selectValue = computed({
  get: () => {
    return props.modelValue;
  },
  set: (val) => {
    emit("update:modelValue", val);
  }
});
getRoleauthorize({ projectId: props.projectId }).then(res => {
  options.value = res.result.data;
  if (props.isall == 1) {
    options.value.unshift({ id: -1, nickname: "所有人" });
  }
});
const isDisabled = (item) => {
  if (props.modelValue && props.isall == 1) {
    if (Array.isArray(props.modelValue)) {
      if (props.modelValue.some(v => v.id == -1)) {
        return item.id != -1
      } else {
        return props.modelValue.length == 0 ? false : item.id == -1
      }
    } else {
      return false
    }
  } else {
    return false
  }
}
</script>
<style lang="scss" scoped></style>
